package com.company.cloud.common.redis;

import java.util.List;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SentinelServersConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StreamOperations;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.util.StringUtils;

import com.company.cloud.common.constant.ConfigConstants;

//@Configuration
//@ConditionalOnProperty(value = "saas.mq.redis.config.enabled", havingValue = "true")
public class RedisMQAutoConfigure {

//	@Bean("redisMQPool")
//	@ConfigurationProperties(prefix = "saas.mq.redis.config.pool")
//	public GenericObjectPoolConfig redisMQPool() {
//		GenericObjectPoolConfig config = new GenericObjectPoolConfig<>();
//		return config;
//	}
//
//	@Bean("standaloneConfigurationMQ")
//	@ConfigurationProperties(prefix = "saas.mq.redis.config")
//	public RedisStandaloneConfiguration standaloneConfigurationMQ() {
//		return new RedisStandaloneConfiguration();
//	}

//    @Bean("redisMQFactory")
//    public LettuceConnectionFactory redisMQFactory(
//    		@Qualifier("redisMQPool") GenericObjectPoolConfig redisMQPool, 
//    		@Qualifier("standaloneConfigurationMQ") RedisStandaloneConfiguration standaloneConfigurationMQ
//    	
//    		) {
//        LettuceClientConfiguration clientConfiguration = LettucePoolingClientConfiguration.builder().poolConfig(redisMQPool).build();
////      new LettuceConnectionFactory(sentinelConfiguration,clientConfiguration)
//        return new LettuceConnectionFactory(standaloneConfigurationMQ, clientConfiguration);
//    }

//	@Bean("redisMQTemplate")
//	public RedisTemplate<String, Object> redisMQTemplate(
//			@Qualifier("redisMQPool") GenericObjectPoolConfig redisMQPool,
//			@Qualifier("standaloneConfigurationMQ") RedisStandaloneConfiguration standaloneConfigurationMQ) {
//		LettuceClientConfiguration clientConfiguration = LettucePoolingClientConfiguration.builder()
//				.poolConfig(redisMQPool).build();
//		LettuceConnectionFactory redisMQFactory = new LettuceConnectionFactory(standaloneConfigurationMQ,
//				clientConfiguration);
//		RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
//		redisTemplate.setKeySerializer(new StringRedisSerializer());
//		redisTemplate.setHashKeySerializer(new StringRedisSerializer());
//		redisTemplate.setHashValueSerializer(new StringRedisSerializer());
//		redisTemplate.setValueSerializer(new StringRedisSerializer());
////	    redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
//		redisTemplate.setConnectionFactory(redisMQFactory);
//		return redisTemplate;
//	}

//    @Bean("redisMQTemplate")
//    public RedisTemplate<String, Object> redisMQTemplate(@Qualifier("redisMQFactory") RedisConnectionFactory redisMQFactory) {
//		RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
//		redisTemplate.setKeySerializer(new StringRedisSerializer());
//		redisTemplate.setHashKeySerializer(new StringRedisSerializer());
//		redisTemplate.setHashValueSerializer(new StringRedisSerializer());
//		redisTemplate.setValueSerializer(new StringRedisSerializer());
////	    redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
//		redisTemplate.setConnectionFactory(redisMQFactory);
//		return redisTemplate;
//    }

//	@Bean("streamOperationsMQ")
//	public StreamOperations<String, String, String> streamOperationsMQ(@Qualifier("redisMQTemplate") RedisTemplate<String, Object> redisTemplate) {
//		return redisTemplate.opsForStream();
//	}

}
